package cn.wolfcode.web.controller;


import cn.wolfcode.domain.JsonResult;
import cn.wolfcode.domain.SystemLog;
import cn.wolfcode.service.ISystemLogService;
import cn.wolfcode.qo.QueryObject;
import cn.wolfcode.util.RequirePermission;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("/systemLog")
public class SystemLogController {

    @Autowired
    private ISystemLogService systemLogService;

    @RequestMapping("/list")
    public String list(Model model, @ModelAttribute("qo") QueryObject qo){
        PageInfo<SystemLog> pageInfo = systemLogService.query(qo);
        model.addAttribute("pageInfo", pageInfo);
        return "systemLog/list";
    }

    @RequestMapping("/delete")
    @RequirePermission(name = "日志删除",expression = "systemLog:delete")
    @ResponseBody
    public JsonResult delete(Long id){
        if (id != null) {
            systemLogService.delete(id);
        }
        return new JsonResult();
    }


    @RequestMapping("/saveOrUpdate")
    @RequirePermission(name = "日志新增/编辑",expression = "systemLog:saveOrUpdate")
    @ResponseBody
    public JsonResult saveOrUpdate(SystemLog systemLog){
        if (systemLog.getId() != null) {
            systemLogService.update(systemLog);
        }else {
            systemLogService.save(systemLog);
        }
        return new JsonResult();
    }
}
